package com.czxy.config;

import com.czxy.auth.util.RsaUtils;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;
import java.security.PublicKey;

/**
 * @author Liuyunqin 17674029449@163.com
 * @date 2018/12/18 15:41
 */
@Data
@ConfigurationProperties(prefix = "sc.jwt")
@Configuration
public class JwtProperties {

    /**
     * 公钥路径
     */
    private String pubFileKey;

    /**
     * 公钥对象
     */
    private PublicKey publicKey;


    @PostConstruct
    public void init() throws Exception {
        // 根据路径获取公钥对象
        try {
            this.publicKey = RsaUtils.getPublicKey(pubFileKey);
        } catch (Exception e) {
            throw new RuntimeException();
        }
    }
}
